
<?php

// on importe le modele utilisateur.php
require 'application/modele/utilisateur.php';
// si l'action n'est pas renseignée, on redirige vers la page d'accueil
//if (!isset($_POST ['action'])) {
//    header ('location: ./index.php');
//}


$action = $_POST ['a'];
if ($action == 'inscription') {

    $nom = $_POST['nom'];
    $prenom = $_POST['prenom'];
    $sexe = $_POST['sexe'];
    $adresse = $_POST['adresse'];
    $cp = $_POST['cp'];
    $ville = $_POST['ville'];
    $pays = $_POST['pays'];
    $email = $_POST['email'];
    $tel = $_POST['tel'];
    $login = $_POST['login'];
    $password = $_POST['password'];

    $user = new Utilisateur($mdb2);
    $result = $user->ajouter($nom, $prenom, $adresse, $tel, $email, $sexe, $cp, $ville, $pays, $login, $password);
    if ($result)
        header('Location: ./index.php?inscription=ok');
    else {
        $smarty->assign('nom', $nom);
        $smarty->assign('prenom', $prenom);
        $smarty->assign('sexe', $sexe);
        $smarty->assign('adresse', $adresse);
        $smarty->assign('cp', $cp);
        $smarty->assign('ville', $ville);
        $smarty->assign('pays', $pays);
        $smarty->assign('email', $email);
        $smarty->assign('tel', $tel);
        $smarty->assign('login', $login);

        $flash['type'] = "error";
        $flash['message'] = "Ce login est déjà utilisé";
        $smarty->assign("flash", $flash);
        $smarty->display("inscription.tpl");
    }
}else{
    $smarty->display("inscription.tpl");
}
?>
